import { useReducer, useState } from "react"
import {produce} from 'immer'
function reducer(state,action){
    switch (action.type){
        case 'add':
            // return{
            //     result: state.result + action.num
            // }
            return produce(state,(state)=>{

            })
        case 'minus':
            return{
                result: state.result - action.num
            }
    }
}

function App() {
    //useReducer接受的第二个的参数作为reducer的第一个参数
    //useReducer接受的第一个的参数作为reducer的第二个参数
  const [res,dispatch]=useReducer(reducer,{a:{b:{c:1}}})

  return (
    <div>
      <h3>{res.result}</h3>
      <button onClick={()=>dispatch({type:'add',num:1})}>+</button>
      <button onClick={()=>dispatch({type:'minus',num:2})}>-</button>
    </div>
  )
}

export default App